<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        body {
            padding: 0px;
            margin: 0px;
        }

        li {
            padding-top: 10px;
            padding-bottom: 10px;
        }

        a {
            text-decoration: none;
        }

        ol {
            width: 85%;
            height: 100%;
        }
    </style>
</head>

<body>
    <ol id="files"></ol>
    <script type="text/javascript" src="./utils.js"></script>
    <script>
        const proto = location.origin.indexOf("https") == 0 ? "https://" : "http://"


        var fileList = []
        var imageParent = document.getElementById("files")
        function parseResult(result) {
            let json;
            if (typeof result === 'string') {
                json = JSON.parse(result);
            } else {
                json = result;
            }
            // const json = JSON.parse(result);
            fileList = json;
            fileList.sort(function (a, b) {
                return a.localeCompare(b, undefined, { sensitivity: 'base' });
            });



            let string = "";
            for (let i = 0; i < json.length; ++i) {
                let name = json[i].substring(json[i].lastIndexOf("/") + 1)

                string += "<li><a class=\"a_link\" href=" + (!pc && name.toLowerCase().lastIndexOf(".pdf") > 0 ? (proto + location.host
                    + "/uploadDir/pdfreader/web/viewer.html?url=") : "") + json[i] + " target=\"_blan\">"


                string += "<text class=\"name_text\">" + name + "</text>"
                string += "</a></li>"
                // string += "<a href="+json[i]+" target=\"_blan\"><img style=\"width:100px;margin:10px;display:block\" src=\""+json[i] ;
                // string += "\"><text></text></a>";
            }
            imageParent.innerHTML = string;
        }
    </script>

    <script type="text/javascript" src="./getrequest.js"></script>
    <script type="text/javascript">
        function getQueryString(name) {
            const url_string = window.location.href;//"/getOtherFiles"//"https://www.baidu.com/t.html?name=mick&age=20"; // window.location.href
            const url = new URL(url_string);
            return url.searchParams.get(name);
        }
        getRequest(proto + location.host
            + "/" + getQueryString("method"), "", function (res) {//"getOtherFiles"
                // console.log(res)
                // console.log(JSON.parse(res))
                parseResult(res)
            })
        // parseResult(["https://divaid.github.io/resources/books/nashannarennagou.txt","https://divaid.github.io/resources/books/guaimomotou.pdf", "https://divaid.github.io/resources/json/books.json"])
    </script>
</body>

</html>